package com.jerry.security.service;

import com.jerry.security.dao.BaseDao;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;

import java.io.Serializable;
import java.util.List;

/**
 * @author Jerry.Wu
 * @description:
 * @date 2018/8/29 18:30
 */
public class BaseService<T, ID extends Serializable> implements BaseServiceInterface<T, ID> {

    @Autowired
    private BaseDao<T, ID> baseDao;

    protected Logger mLogger;

    public BaseService() {
        mLogger = LogManager.getLogger(this.getClass());
    }

    public BaseDao<T, ID> getDao() {
        return baseDao;
    }

    @Override
    public void delete(T entity) {
        getDao().delete(entity);
    }

    @Override
    public void deleteById(ID id) {
        getDao().deleteById(id);
    }

    @Override
    public T save(T entity) {
        return getDao().save(entity);
    }

    @Override
    public T load(ID id) {
        return getDao().getOne(id);
    }

    @Override
    public List<T> findAll() {
        return getDao().findAll();
    }

    @Override
    public List<T> findAll(Sort sort) {
        return getDao().findAll(sort);
    }

}
